package view.listener;

import model.Constants;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;

import control.Storage;
import control.Util;

public class StartButtonListener extends SelectionAdapter {

	@Override
	public void widgetSelected(SelectionEvent arg0) {

		Control children[] = arg0.display.getActiveShell().getChildren();

		for (int i = 0; i < children.length; i++) {

			if (children[i] instanceof Text) {
				Text text = (Text) children[i];
				switch (i) {
				case 1:

					if (Util.validateInput(text.getText())) {
						Storage.getInstance().setPlayer(text.getText());
					} else {
						Storage.getInstance().setPlayer(Constants.PLAYER);
					}

					break;
				case 3:
					if (Util.validateInput(text.getText())) {
						Storage.getInstance().setEnemy(text.getText());
					} else {
						Storage.getInstance().setEnemy(Constants.ENEMY);
					}

					break;

				case 5:
					if (Util.validateInput(text.getText())) {
						Storage.getInstance().setSize(
								Integer.valueOf(text.getText()));
					}

					break;

				default:
					break;
				}

			}
		}

		arg0.display.getActiveShell().dispose();

	}

}
